package zuoye726;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


public class Demo5 {
	public static void main(String[] args) throws Exception {
		
		ArrayList<Character> list=new ArrayList<>();
		FileInputStream readfile=new FileInputStream("Demo5.txt"); 
		//FileOutputStream writefile=new FileOutputStream("Demo5.txt");
		String str="";
		byte[] b=new byte[1024];
		int len=0;
		while((len=readfile.read(b))!=-1){
			 str=new String(b,0,len);	
		}
		readfile.close();
	    for(int i=0;i<str.length();i++){
	     list.add(str.charAt(i));
	    }
	    System.out.println(list);

	   String collect3 = list.stream().sorted().filter(t->t!='-').map(t->t.toString()).collect(Collectors.joining("-"));
	   System.out.println(collect3);
	   byte[] bytes = collect3.getBytes();
	   FileOutputStream writefile=new FileOutputStream("Demo5.txt");
	   writefile.write(bytes);
	   writefile.close();
	
	
	
	
	
	
	
	
	
	
	
	
	}
	
}
